package cn.itcast.n8;

import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


/**
 * @author: AirMan
 * @date: 2025/4/25 13:58
 * @description:
 */
public class TestCountDownLatch_my {
    public static void main(String[] args) throws InterruptedException {

        ScheduledExecutorService pool = Executors.newScheduledThreadPool(10);
        CountDownLatch latch = new CountDownLatch(10);
        Random r = new Random();
        String[] all = new String[10];

        for (int j = 0; j < 10; j++) {
            int k = j;
            pool.execute(() -> {
                for (int i = 0; i <= 100; i++) {
                    try {
                        TimeUnit.MILLISECONDS.sleep(r.nextInt(100));
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    all[k] = i + "%";
                    System.out.print("\r" + Arrays.toString(all));
                }
                latch.countDown();
            });
        }

        latch.await();
        System.out.println("\n游戏开始");
        pool.shutdownNow();

    }
}
